package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 销售机会表
 */
@Entity
public class Opportunity {
    private int oppoId;
    private String oppoName;
    private Date stateDate;
    private Date planIdealTime;
    private String saleSource;
    private String detail;
    private String aboutDocument;
    private Date nextContactTime;
    private Integer isOn;

//    private Integer customerId;
    private Customer customer;              // 客户 多对一
    //    private Integer empId;
    private Emp worker;                       // 业务员 一对一
//    private Integer oppoStateId;
    private OppoState state;                //状态 多对一
//    private Integer offerId;
    private List<DetailOffer> oppoProList;               //所报产品一对多

    @OneToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomer() { return customer; }

    public void setCustomer(Customer customer) { this.customer = customer; }

    @ManyToOne
    @JoinColumn(name = "emp_id", referencedColumnName = "emp_id")
    public Emp getWorker() { return worker; }

    public void setWorker(Emp worker) { this.worker = worker; }

    @ManyToOne
    @JoinColumn(name = "oppo_state_id", referencedColumnName = "oppo_state_id")
    public OppoState getState() { return state; }

    public void setState(OppoState state) { this.state = state; }

    @OneToMany(mappedBy = "opportunity")
    public List<DetailOffer> getOppoProList() {
        return oppoProList;
    }

    public void setOppoProList(List<DetailOffer> oppoProList) {
        this.oppoProList = oppoProList;
    }

    @Id
    @Column(name = "oppo_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getOppoId() {
        return oppoId;
    }

    public void setOppoId(int oppoId) {
        this.oppoId = oppoId;
    }

    @Basic
    @Column(name = "oppo_name", nullable = true, length = 40)
    public String getOppoName() {
        return oppoName;
    }

    public void setOppoName(String oppoName) {
        this.oppoName = oppoName;
    }

    @Basic
    @Column(name = "state_date", nullable = true)
    public Date getStateDate() {
        return stateDate;
    }

    public void setStateDate(Date stateDate) {
        this.stateDate = stateDate;
    }

    @Basic
    @Column(name = "plan_ideal_time", nullable = true)
    public Date getPlanIdealTime() {
        return planIdealTime;
    }

    public void setPlanIdealTime(Date planIdealTime) {
        this.planIdealTime = planIdealTime;
    }

    @Basic
    @Column(name = "sale_source", nullable = true, length = 0)
    public String getSaleSource() {
        return saleSource;
    }

    public void setSaleSource(String saleSource) {
        this.saleSource = saleSource;
    }

    @Basic
    @Column(name = "detail", nullable = true, length = 40)
    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    @Basic
    @Column(name = "about_document", nullable = true, length = 40)
    public String getAboutDocument() {
        return aboutDocument;
    }

    public void setAboutDocument(String aboutDocument) {
        this.aboutDocument = aboutDocument;
    }

    @Basic
    @Column(name = "next_contact_time", nullable = true)
    public Date getNextContactTime() {
        return nextContactTime;
    }

    public void setNextContactTime(Date nextContactTime) {
        this.nextContactTime = nextContactTime;
    }

    @Basic
    @Column(name = "is_on", nullable = true)
    public Integer getIsOn() {
        return isOn;
    }

    public void setIsOn(Integer isOn) {
        this.isOn = isOn;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Opportunity that = (Opportunity) o;
        return oppoId == that.oppoId &&
                Objects.equals(oppoName, that.oppoName) &&
                Objects.equals(stateDate, that.stateDate) &&
                Objects.equals(planIdealTime, that.planIdealTime) &&
                Objects.equals(saleSource, that.saleSource) &&
                Objects.equals(detail, that.detail) &&
                Objects.equals(aboutDocument, that.aboutDocument) &&
                Objects.equals(nextContactTime, that.nextContactTime) &&
                Objects.equals(isOn, that.isOn) &&
                Objects.equals(customer, that.customer) &&
                Objects.equals(worker, that.worker) &&
                Objects.equals(state, that.state) &&
                Objects.equals(oppoProList, that.oppoProList);
    }

    @Override
    public int hashCode() {
        return Objects.hash(oppoId, oppoName, stateDate, planIdealTime, saleSource, detail, aboutDocument, nextContactTime, isOn, customer, worker, state, oppoProList);
    }
}
